package dev.erge.net;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author erge
 */
public class InetAdressSample {
    public static void main(String[] args) {
        try {
            InetAddress addr1 = InetAddress.getByName("127.0.0.1");
            InetAddress addr2 = InetAddress.getByName("www.baidu.com");
            System.out.println(addr1);
            System.out.println(addr2);
            InetAddress addr3 = InetAddress.getByName("localhost");
            System.out.println(addr3);
            InetAddress addr4 = InetAddress.getLocalHost();
            System.out.println(addr4);
            System.out.println(Arrays.toString(addr2.getAddress()));
            System.out.println(addr2.getCanonicalHostName());
            System.out.println(addr2.getHostAddress());
            System.out.println(addr2.getHostName());
        } catch (UnknownHostException ex) {
            Logger.getLogger(InetAdressSample.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
